WEBVTT

00:00.670 --> 00:02.140
Hello and welcome back to the call.

00:02.140 --> 00:05.840
So now we are coming to the core methods of my old course.

00:05.860 --> 00:11.560
So when it comes to large scale and numerical operations none pay as much faster than the pace and standard

00:11.560 --> 00:12.140
library.

00:12.160 --> 00:18.420
Because they are we can use spectre raised element y's operations and we do not need any follow up size

00:18.430 --> 00:20.150
statements and so on.

00:20.380 --> 00:26.680
And in this sense though we can also save many lines of code with an empire in Python we can measure

00:26.680 --> 00:30.010
the time our machine needs for the execution of code.

00:30.070 --> 00:37.030
So with the magic function time it so it's called magic because it starts as a percentage sign.

00:37.390 --> 00:43.720
So there are many so-called magic functions and time it runs the code multiple times and returns as

00:43.870 --> 00:46.260
the ever it's execution time.

00:46.330 --> 00:53.740
So but now let's first impact an umpire and then reset the size of our lists and our race.

00:53.740 --> 01:00.170
First of all to three so we only have three elements and then we create an umpire array with three elements.

01:01.000 --> 01:02.560
So the length is three.

01:02.560 --> 01:05.800
So we have an array that's 0 1 and 2.

01:05.800 --> 01:13.150
And also we create a list with the range function and three elements as you can see now here we have

01:13.180 --> 01:14.970
our array and our list l.

01:15.040 --> 01:20.530
And now we measure the time our machine needs to add to each element in our array and the integer to

01:27.840 --> 01:31.030
so it's 660 nanoseconds.

01:31.290 --> 01:33.500
And the same we are doing now for the list.

01:33.510 --> 01:35.070
So we have a list comprehension.

01:35.110 --> 01:42.090
So for each element in our list there are only three elements we add to let's also measured the time

01:42.090 --> 01:45.930
here.

01:45.940 --> 01:48.600
Here we have two hundred seventy six nanoseconds.

01:48.640 --> 01:54.880
So you can see in the very small scale operation num pi is slower here than than the python standard

01:54.880 --> 01:59.400
library and we can also try other operations like multiplication.

01:59.410 --> 02:02.590
So we multiply each element of our array by two

02:09.210 --> 02:15.240
so we get six hundred fifty nine nanoseconds and we do the same four for the list elements multiplying

02:15.240 --> 02:15.750
by two

02:18.640 --> 02:24.020
and also here two hundred seventy nanoseconds at least at a small scale with only three elements num

02:24.060 --> 02:36.140
pi is slower let's go onto squaring our elements and let's see the average time for the man pi package.

02:36.170 --> 02:42.890
So it's five hundred fifty seven nanoseconds and we do the same with the list comprehension

02:53.700 --> 03:01.710
so now obviously here with the operations squaring num pi is faster than than the python standard library.

03:01.710 --> 03:08.030
So before here with additional multiplication non PI was two times slower than the python standard library

03:08.040 --> 03:11.120
so in the end it also depends which operation you have under.

03:11.220 --> 03:15.120
Let's also try to get to the square root of the number package

03:22.570 --> 03:26.230
eight hundred seventy six nanoseconds and let's do the same.

03:26.260 --> 03:27.530
This list comprehension

03:32.890 --> 03:35.640
now again here the pace and standard library is faster.

03:35.740 --> 03:39.340
So it depends on the operation of the type of the operation.

03:39.340 --> 03:42.840
All right so but it seems very a very small scale that.

03:42.880 --> 03:43.070
Yeah.

03:43.090 --> 03:45.720
That's not really an advantage of the number I package.

03:45.730 --> 03:55.440
But um let's increase our size of elements from three to let's say 1 million.

03:55.880 --> 03:58.460
So we have from our array 1 million elements.

03:58.580 --> 04:04.190
And also on our list and let's read from the whole thing.

04:04.190 --> 04:09.470
So let's begin with Ed..

04:09.810 --> 04:12.840
So now we have two point two three milliseconds for the month.

04:12.860 --> 04:13.770
Hi Ed..

04:13.770 --> 04:16.610
Let's see what we get with the list comprehension.

04:24.610 --> 04:29.800
Now we get your ninety two point eight milliseconds so Nampa here was about the hour forty or forty

04:29.800 --> 04:32.560
five times faster than Python standard library.

04:32.560 --> 04:38.380
And let's also try the multiplication with one million elements.

04:38.380 --> 04:41.790
So now I'm pi needs on average two points with six milliseconds.

04:41.890 --> 04:44.950
And let's try the python standard library

04:52.270 --> 04:59.800
also here ninety two point eight milliseconds so about forty forty five times slower than empire and

04:59.800 --> 05:01.360
let's go onto a squaring

05:05.670 --> 05:09.010
two points three eight milliseconds for the number pi package.

05:09.480 --> 05:11.060
And the list comprehension

05:13.690 --> 05:21.630
362 milliseconds num pi is about 250 times faster than the python standard library.

05:21.720 --> 05:23.790
And last but not least the square root

05:32.820 --> 05:42.750
nine point four one milliseconds and this comprehension 217 milliseconds now pays about twenty times

05:42.750 --> 05:47.940
faster than the python standard library so we have seen that.

05:47.980 --> 05:48.190
Yeah.

05:48.240 --> 05:54.360
I'm pi is when it comes to very large scale operations with uh thousands or millions of elements.

05:54.370 --> 05:56.590
The number is really much faster.

05:56.590 --> 06:03.110
So on average about 50 to a 100 times faster than the python standard library.

06:03.250 --> 06:05.410
And it also depends on the type of operations.

06:05.410 --> 06:10.810
All right so this is it for the time being and in the next session we will have a small case study where

06:10.810 --> 06:15.400
we also have a look at the performance between num pi enterprise and standard library so hope to see

06:15.400 --> 06:16.090
you there by.
